package login;

import util.InputUtil;
import view.GoodInfoView;
import view.MemberView;
import view.ProductView;

/**
 * @classname:admin
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/31 16:34
 * @version: 0.1
 * @since:1.8
 */
public class Admin {
    private static int result;

    public Admin() {
    }

    public static void showMethod() {
        System.out.println("请选择要管理的模块\n" +
                "-----------------------------\n" +
                "1.类型管理 2.商品管理 3.会员管理 4.返回重新登陆");
        int num = InputUtil.inputInt();
        switch (num) {
            case 1:
                typeMag();
                break;
            case 2:
                goodsMag();
                break;
            case 3:
                memberMag();
                break;
            case 4:
                Index.login();
                break;
        }
        continues();
    }

    private static void typeMag() {
        System.out.println("欢迎进入商品类型管理模块");
        System.out.println("请选择要操作的功能\n" +
                "-----------------------------\n" +
                "1.增加商品类型 2.删除商品类型 3.修改商品类型  4.查询父类型下的产品");
        int num = InputUtil.inputInt();
        switch (num) {
            case 1:
                System.out.println(ProductView.addProduct());
                break;
            case 2:
                System.out.println(ProductView.deleteProductRelyOrNo());
                break;
            case 3:
                ProductView.updateProdut();
                break;
            case 4:
                ProductView.showAllProductHaveEvery();
                break;
        }
        continues();
    }


    private static void goodsMag() {
        System.out.println("欢迎进入商品管理模块");
        System.out.println("请选择要操作的功能\n" +
                "-----------------------------\n" +
                "1.增加商品信息 2.删除商品信息 3.修改商品信息 4.查询商品信息 5.展示所有商品信息");
        int num = InputUtil.inputInt();
        switch (num) {
            case 1:
                System.out.println("录入新的商品信息");
                System.out.println("----------------");
                System.out.println(GoodInfoView.addGoodInfo());
                break;
            case 2:
                System.out.println("所有商品信息如下");
                GoodInfoView.showAll();
                System.out.println(GoodInfoView.deleteGoodRelyOrFake());
                break;
            case 3:
                System.out.println("所有商品信息如下");
                GoodInfoView.showAll();
                System.out.println(GoodInfoView.updateGoodInfobyParams());
                break;
            case 4:
                GoodInfoView.selectGoodByParams();
                break;
            case 5:
                GoodInfoView.showAll();
                break;
        }
        continues();
    }


    private static void memberMag() {
        System.out.println("欢迎进入会员管理模块");
        System.out.println("请选择要操作的功能\n" +
                "-----------------------------\n" +
                "1.增加会员信息 2.删除会员信息 3.更改会员信息 4.查询会员信息 5.会员充值");
        int num = InputUtil.inputInt();
        switch (num) {
            case 1:
                System.out.println("录入新的会员信息");
                System.out.println("----------------");
                System.out.println(MemberView.addMember());
                break;
            case 2:
                result = MemberView.deleteMemberById();
                checkResult(result, "删除");
                break;
            case 3:
                System.out.println(MemberView.updateMemberInfo());
                break;
            case 4:
                MemberView.selectAll();
                break;
            case 5:
                result = MemberView.updateMemberBalance();
                checkResult(result, "充值");
                break;
        }
        continues();
    }


    private static void checkResult(int results, String msg) {
        if (results == 0) {
            System.out.println(msg + "失败");
        } else if (results == 1) {
            System.out.println(msg + "成功");
        }
    }


    private static void continues() {
        System.out.println("是否继续本功能模块或选择其他功能模块1.商品类型管理 2.商品管理 3.会员管理 4.退出至主页面");
        int num = InputUtil.inputInt();
        switch (num) {
            case 1:
                typeMag();
                break;
            case 2:
                goodsMag();
                break;
            case 3:
                memberMag();
                break;
            case 4:
                showMethod();
                break;
        }
    }
}
